package desgin.pattern.behavior.observer;

import java.util.ArrayList;
import java.util.List;
/**
 * 
 * @Type Subject
 * @Desc 抽象主题角色类
 * @author Administrator
 * @date 2015年3月11日
 * @Version V1.0
 */
public abstract class Subject {
    private List<Observer> list = new ArrayList<Observer>();

    protected void attach(Observer observer) {
        list.add(observer);
        System.out.println("attach an observer");
    }

    protected void detach(Observer observer) {
        list.remove(observer);
        System.out.println("detach an observer");
    }

    protected void nodifyObservers(String newstate) {
        for (Observer obs : list) {
            obs.update(newstate);
        }
    }

}
